const fs = require('fs')
const path = require('path')

const useRoutes = function () {
  try {
    const files = fs.readdirSync(__dirname)
    for (let i = 0; i < files.length; i ++) {
      if (files[i] === 'index.js') continue

      const router = require(`${path.resolve(__dirname, files[i])}`)
      // console.log('router: ---', router)
      this.use(router.routes())
      this.use(router.allowedMethods())
    } 
  } catch (error) {
    console.log(error.message)
  }

}

module.exports = useRoutes
